package com.lai.security;

import com.lai.dao.JdbcUserDao;
import com.lai.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;


@Component
public class MyUserService implements UserDetailsService {
    @Autowired
    private JdbcUserDao userDao;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user= userDao.getUserByUsername(s);
        if(user==null)throw  new UsernameNotFoundException("user not found");
        return user;
    }
}
